home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / fdform18.zip / READBOOT.PAS < prev    next >
Pascal/Delphi Source File  |  1991-07-21  |  4KB  |  133 lines

  1. {$A+,B-,D+,E-,F-,I-,L+,N-,O-,R-,S-,V-}
  2. {$M 4096,0,655360}
  3. PROGRAM READBOOT;
  4.  
  5.   {READBOOT - Get Boot Sector from file/Write File to Boot-Sector - Ver 1.21}
  6.   {Compiled with Turbo-Pascal Ver 6.0}
  7.   {Does not compile with earlier versions of Turbo-Pascal}
  8.  
  9. USES dos,auxdos,diskio;
  10.  
  11. VAR para   : String[50];
  12.   fn       : String[50];
  13.   f        : FILE;
  14.   lw       : Byte;
  15.   ok       : Boolean;
  16.   written  : Word;
  17.   readdisk : Boolean;
  18.   FileBoot : ^bpbtyp;
  19.   ysec     : LongInt;
  20.   stderr   : Text;
  21.  
  22.   PROCEDURE SyntaxError;
  23.   BEGIN
  24.     WriteLn(stderr,'Syntax Error.');
  25.     WriteLn(stderr);
  26.     WriteLn(stderr,'Syntax is:  READBOOT <drive>: <file>  (write Boot-Sector to file)');
  27.     WriteLn(stderr,'            READBOOT <file> <drive>:  (read Boot-Sector from file)');
  28.     WriteLn(stderr);
  29.     WriteLn(stderr,'Exapmles: READBOOT A: C:\DISKS\BOOT1.SYS');
  30.     WriteLn(stderr,'          READBOOT C:\DISKS\BOOT1.SYS A:');
  31.     WriteLn(stderr);
  32.     Halt(1);
  33.   END;
  34.  
  35.   PROCEDURE BootError;
  36.   BEGIN
  37.     WriteLn(stderr,'File ',fn,' is no Boot-Sector image.');
  38.     Close(f);
  39.     Halt(9);
  40.   END;
  41.  
  42.   PROCEDURE DosError;
  43.   BEGIN
  44.     WriteLn(stderr,'This program requires DOS 3.20 or higher.');
  45.     Halt(10);
  46.   END;
  47.  
  48. BEGIN
  49.   WriteLn;
  50.   WriteLn('READBOOT-Read/Write Boot-Sector from/to File  V1.21');
  51.   WriteLn('Copyright (c) 1988 - 1991, Christoph H. Hochstätter');
  52.   WriteLn;
  53.   IF Swap(DosVersion)<$314 THEN DosError;
  54.   IF (Length(ParamStr(1))=2) AND (Length(ParamStr(2))=2) THEN SyntaxError;
  55.   IF Length(ParamStr(1))=2 THEN BEGIN
  56.     para:=ParamStr(1);
  57.     fn:=ParamStr(2);
  58.     readdisk:=True;
  59.   END ELSE IF Length(ParamStr(2))=2 THEN BEGIN
  60.     para:=ParamStr(2);
  61.     fn:=ParamStr(1);
  62.     readdisk:=False;
  63.   END ELSE
  64.     SyntaxError;
  65.   IF fn='' THEN SyntaxError;
  66.   FOR lw:=1 TO Length(fn) DO fn[lw]:=Upcase(fn[lw]);
  67.   IF para[2]<>':' THEN SyntaxError;
  68.   lw:=Ord(Upcase(para[1]))-$40;
  69.   BootSec.init(ok);
  70.   IF NOT(ok) THEN BEGIN
  71.     WriteLn(stderr,'Not enough Memory.');
  72.     Halt(4);
  73.   END;
  74.   BootSec.Readx(lw);
  75.   IF BootSec.UnknownDrive THEN BEGIN
  76.     WriteLn(stderr,'Drive does not exist.');
  77.     Halt(3);
  78.   END;
  79.   IF (BootSec.Status AND $9200) <> 0 THEN BEGIN
  80.     WriteLn(stderr,'READBOOT does not work with a SUBST/ASSIGN/NETWORK Drive.');
  81.     Halt(2);
  82.   END;
  83.   WITH BootSec.bpb^ DO BEGIN
  84.     WriteLn('Information from the floppy:');
  85.     WriteLn('Sectors/Track: ',spt);
  86.     WriteLn('Sides        : ',hds);
  87.     WriteLn('Bytes total  : ',DiskSize(lw));
  88.     WriteLn('Bytes free   : ',DiskFree(lw));
  89.     WriteLn;
  90.     Assign(f,fn);
  91.     IF readdisk THEN BEGIN
  92.       FileMode:=OWriteOnly OR ODenyWrite;
  93.       Rewrite(f,1);
  94.       Reset(f,1);
  95.     END ELSE BEGIN
  96.       FileMode:=OReadOnly OR ODenyWrite;
  97.       Reset(f,1);
  98.     END;
  99.     IF IoResult<>0 THEN BEGIN
  100.       WriteLn(stderr,'File ',fn,' cannot be openend.');
  101.       Close(f);
  102.       Halt(6);
  103.     END;
  104.     IF NOT(readdisk) THEN BEGIN
  105.       IF FileSize(f)<>512 THEN BootError;
  106.       GetMem(FileBoot,512);
  107.       BlockRead(f,FileBoot^,512,written);
  108.       IF (written<>512) OR
  109.       (FileBoot^.boot_code[511]<>$AA) OR
  110.       (FileBoot^.boot_code[510]<>$55) THEN BEGIN
  111.         BootError;
  112.       END;
  113.       WriteLn('Sector-Type  : ',FileBoot^.oem);
  114.       WriteLn;
  115.       Seek(f,0);
  116.     END;
  117.     IF readdisk THEN BEGIN
  118.       BlockWrite(f,BootSec.bpb^,512,written);
  119.       IF written<>512 THEN BEGIN
  120.         WriteLn(stderr,'Disk full - File: ',fn);
  121.         Close(f);
  122.         Halt(19);
  123.       END;
  124.     END ELSE BEGIN
  125.       jmp:=FileBoot^.jmp;
  126.       boot_code:=FileBoot^.boot_code;
  127.       oem:=FileBoot^.oem;
  128.       BootSec.writex(lw);
  129.     END;
  130.     Close(f);
  131.   END;
  132. END.
  133.